<?php $this->load->view('admin_home/_header') ?>
<?php $this->load->view('message') ?>


<div class="container">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">添加考点</h3>
		</div>
		<div class="panel-body">
			<?php echo validation_errors(); ?>
			<form id="test_point_add_form" class="form-horizontal" action="<?php echo site_url('admin_test_point/add')?>" method="post">
				<input type="text" id="knowledge_point_number" name="knowledge_point_number" value="1" class="hidden">
				<fieldset>
					<div class="form-group">
						<label class="col-lg-2 control-label">考点内容:</label>
						<div class="col-lg-8">
							<input class="form-control" type="text" id="content" name="content"/>
						</div>
					</div>
					<div class="form-group">
						<label class="col-lg-2 control-label">相关模块:</label>
						<div class="col-lg-8">
							<select class="selectpicker form-control" multiple data-live-search="true" 
							data-style="btn-primary" multiple data-selected-text-format="count" name="relative_modules[]">
								<?php foreach ($modules as $item ): ?>
									<option value="<?=$item['id']?> ">
										<?=$item['name']?>
									</option>
								<?php endforeach ?>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="select" class="col-lg-2 control-label">知识点：</label>
						<div class="col-lg-10">
							<div class="row" id="knowledge_point_row_1">
								<div class="col-lg-7">
									<input type="text" class="form-control" id="knowledge_point_input_1" name="knowledge_point_input_1" /> </div>
								<div class="col-lg-4">
									<a class="btn btn-primary" id="knowledge_point_button_1" onclick="add_knowledge(1)">添加</a>
								</div>
							</div>
						</div>
					</div>

					<div class="form-group">
						<label class="col-lg-2 control-label"></label>
						<div class="col-lg-8">
							<button class="btn btn-primary" type="submit">提交</button>
						</div>
					</div>
				</fieldset>
			</form> 
		</div>
		
	</div>
</div>

<?php $this->load->view('admin_home/_footer')?>



<script tyep="text/javascript">
  $().ready(function(){
    $("#test_point_li").addClass("active"); 

 	$('.selectpicker').selectpicker();


    $("#test_point_add_form").validate({
		rules:{
			content:
			{
				required:true,
				maxlength:400
			},
			knowledge_point_input_1:
			{
				required:true,
				maxlength:400
			}
		}
	}); 

  });

  function add_knowledge(id)
	{
		if($("#knowledge_point_input_"+id).val()=="")
		{
			alert("添加时不能为空");
		}
		else
		{
			$("#knowledge_point_button_"+id).text("删除");
			$("#knowledge_point_button_"+id).attr("onclick","delete_knowledge("+id+")");
			nextId=id+1;
			html="<div class='row' id='knowledge_point_row_"+nextId+"'>"+
								"<div class='col-lg-7'>"+
									"<input type='text' class='form-control' name='knowledge_point_input_"+nextId+"' id='knowledge_point_input_"+nextId+"'></div>"+
								"<div class='col-lg-4'>"+
									"<a class='btn btn-primary' id='knowledge_point_button_"+nextId+"' onclick='add_knowledge("+nextId+")'>添加</a>"+
								"</div>"+
							"</div>";
			$("#knowledge_point_row_"+id).after(html);
			$("#knowledge_point_number").val(nextId);
			$("#knowledge_point_input_"+id).rules("add",{required:true,maxlength:150});
		}
	}

	function delete_knowledge(id)
	{
		$("#knowledge_point_row_"+id).remove();
		$("#knowledge_point_input_"+id).rules("remove");
	}
</script>